package com.cn.delan.web.mvc.admin.action;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

import com.cn.delan.core.util.StringUtil;
import com.cn.delan.web.mvc.admin.AdminConst;
import com.cn.delan.web.mvc.admin.bean.UserBean;
import com.cn.delan.web.mvc.admin.service.IUserService;
import com.cn.delan.web.mvc.core.action.AbstractAction;
/**
 * 删除用户
 * @author BingGo
 *
 */
public class DelUserAction extends AbstractAction {

	private IUserService<UserBean> userService;
	
	public IUserService<UserBean> getUserService() {
		return userService;
	}
	public void setUserService(IUserService<UserBean> userService) {
		this.userService = userService;
	}

	@Override
	public ModelAndView handle(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String oid = this.getParameter("_oid");
		PrintWriter out = this.getWriter();
		if(!StringUtil.isEmpty(oid)){
			//删除操作
			try{
				if(this.userService.del(oid)){
					//删除成功
					out.print(this.getMessage(AdminConst.MESSAGE_USER_DELSUCCESS));
				}else{
					//删除失败
					out.print(this.getMessage(AdminConst.MESSAGE_USER_DELFAIL));
				}
			}catch(Exception e){
				//删除失败
				e.printStackTrace();
				out.print(this.getMessage(AdminConst.MESSAGE_USER_DELFAIL));
			}
			return null;
		}else{
			//用户不存在
			out.print(this.getMessage(AdminConst.MESSAGE_USER_NOTEXISTS));
			return null;
		}
	}

}
